package com.sg.file.transform.provider.service;

import com.sg.file.transform.api.ITransformService;
import com.sg.file.transform.api.dto.TransformReqeust;
import com.sg.file.transform.provider.center.TransformCenter;
import com.sg.file.transform.provider.center.TransformCode;
import com.sg.file.transform.provider.center.TransformCodeFactory;
import com.sg.file.transform.provider.event.AsynTransformPublisher;
import it.sauronsoftware.jave.EncoderException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;

/**
 * Created by asus on 2018/7/17.
 */
@Service
@Slf4j
public class TransformService implements ITransformService {
    @Autowired
    private TransformCodeFactory transformCodeFactory;

    @Autowired
    private AsynTransformPublisher asynTransformPublisher;


    @Override
    public void doTransformAsyn(TransformReqeust... transformReqeusts) {
        for(TransformReqeust transformReqeust:transformReqeusts) {
            if(transformReqeust==null){
                continue;
            }
            //将转换请求交给事件发布器发布
            asynTransformPublisher.publish(transformReqeusts);
        }
    }

    @Override
    public boolean doTransformSync(TransformReqeust transformReqeust) {
        //执行转化
        return TransformCenter.doTransform(transformReqeust);
    }
}
